<?php

class admin_model_system_log extends model
{

    public function get_logs($user_id = 0, $key = '', $offset = 0, $limit = 20)
    {
        $query = 'SELECT * FROM `bone_system_log` WHERE 1 ';
        if ($user_id !== 0) $query .= ' AND `user_id`='.$user_id;
        if ($key !== '') $query .= ' AND `title` LIKE \'%' . $key . '%\'';
        
        $query .= ' ORDER BY `id` DESC';
        
        $db = bone::get_db();
        return $db->get_objs($query, $offset, $limit);
    }

    
    public function get_log_sum($user_id = 0, $key = '')
    {
        $query = 'SELECT COUNT(*) FROM `bone_system_log` WHERE 1 ';
        if ($user_id !== 0) $query .= ' AND `user_id`='.$user_id;
        if ($key !== '') $query .= ' AND `title` LIKE \'%' . $key . '%\'';
        $db = bone::get_db();
        return $db->get_result($query);
    }

    public function get_admins()
    {
        $query = 'SELECT * FROM `bone_user` WHERE `is_admin`=1';
        
        $db = bone::get_db();
        return $db->get_objs($query);
    }

}
?>